package com.hl.sfzy.controller;

import com.hl.sfzy.entity.Secret;
import com.hl.sfzy.service.SecretService;
import com.hl.sfzy.utils.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/secret")
public class SecretController {
	@Autowired
	private SecretService secretService;

	@PostMapping("/add")
	public R add(@RequestBody Secret secret) {
		int result = secretService.add(secret);
		if (result != 0) {
			return R.ok("添加成功");
		} else {
			return R.fail("添加失败");
		}
	}

	@PutMapping("/edit")
	public R edit(@RequestBody Secret secret) {
		int result = secretService.edit(secret);
		if (result != 0) {
			return R.ok("修改成功");
		} else {
			return R.fail("修改失败");
		}
	}

	@DeleteMapping("/remove")
	public R remove(Integer secretId) {
		int result = secretService.remove(secretId);
		if (result != 0) {
			return R.ok("删除成功");
		} else {
			return R.fail("删除失败");
		}
	}

	@DeleteMapping("/removeBatch")
	public R removeBatch(Integer[] secretIds) {
		int result = secretService.removeBatch(secretIds);
		if (result != 0) {
			return R.ok("批量删除成功");
		} else {
			return R.fail("批量删除失败");
		}
	}

	@GetMapping("/find")
	public R find() {
		return R.ok(secretService.find());
	}

	@GetMapping("/findById")
	public R findById(Integer secretId) {
		return R.ok(secretService.findById(secretId));
	}

	@GetMapping("/findByPage")
	public R findByPage(
			@RequestParam(required = false ,defaultValue = "1")int pageNum,
			@RequestParam(required = false,defaultValue = "5") int pageSize, Secret secret) {
		return R.ok(secretService.findByPage(pageNum, pageSize, secret));
	}
}
